<template>
	<view>
		<view class="" v-for="(item, index) in MyAdviceList" :key="index">
			<uni-card type="line" :title="item.feedbackTitle" :extra="item.feedbackTime"
				:thumbnail="imageList(item.feedbackPhoto)">
				<mp-html class="notice-content content" :content="item.feedbackContent" />
				<template v-slot:actions>
					<view class="card-actions">
						<view class="card-actions-item" v-show="item.replyStatus==0" @click="recal(item.id)">
							<text class="card-actions-item-text">撤回</text>
						</view>
						<view class="card-actions-item" v-show="item.replyStatus==0" @click="goUploadAdvice(item)">
							<text class="card-actions-item-text">修改</text>
						</view>

						<view v-show="item.replyStatus==1">
							<text style="color: red;" @click="yesReply()">已回复</text>
						</view>
						<view v-show="item.replyStatus==1">
							<text @click="delImg(item.id)">删除</text>
						</view>
						<view class="card-actions-item" @click="showAdvice(item)">
							<text class="card-actions-item-text">查看</text>
						</view>
					</view>
				</template>
			</uni-card>
		</view>
	</view>
</template>

<script>
	import {
		RecallMyAdvice,
		DeleteMyAdvice
	} from '@/api/advice/advice.js'
	export default {
		name: "my-advice",
		props: {
			MyAdviceList: {
				type: Array,
				default: () => []
			},
		},
		data() {
			return {
				s: [],
			};
		},
		methods: {
			delImg(id) {
				uni.showModal({
					title: '提示',
					content: '是否删除当前信息',
					success: (res) => {
						if (res.confirm) {
							DeleteMyAdvice(id).then(res => {
								if (res.code == 200) {
									this.$emit("refresh");
									uni.showToast({
										title: '删除成功',
										duration: 2000,
									});

								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			yesReply() {
				uni.showModal({
					content: "请及时查看回复内容",
					showCancel: false,
					success: function(res) {
						if (res.confirm) {
							// console.log('用户点击确定');
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			showAdvice(event) {
				uni.navigateTo({
					url: '/pages/home/adviceDetails/index?item=' + encodeURIComponent(JSON.stringify(event))
				})
			},
			recal(id) {
				uni.showModal({
					title: '提示',
					content: '是否撤回当前信息',
					success: (res) => {
						if (res.confirm) {
							RecallMyAdvice(id).then(res => {
								if (res.code == 200) {
									this.$emit("refresh");
									uni.showToast({
										title: '撤回成功',
										duration: 2000,
									});

								}
							})
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			goUploadAdvice(item) {
				uni.navigateTo({
					url: '/pages/home/upload-active/index?id=' + item.id
				})
			},
		},
		computed: {
			imageList() {
				return function(e) {
					if (e == null) {
						return '@/static/images/head.jpg'
					}
					return e.split(",")[0]
				}
			},
		},
	}
</script>

<style>
	.chahui {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.content {
		display: block;
		font-family: PingFangSC-Regular;
		font-size: 28rpx;
		color: #482929;
		letter-spacing: 0;
		line-height: 40rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: normal;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.card-actions {
		display: flex;
		height: 60rpx;
		margin-right: 10rpx;
		justify-content: space-between;
	}

	.card-actions-item-text {
		font-size: 28rpx;
	}

	.close {
		width: 38rpx;
		height: 38rpx;
		position: absolute;
		top: 0rpx;
		right: 0rpx;
	}
</style>
